package com.richie696.catalina.connector;

import com.richie696.catalina.Engine;
import com.richie696.catalina.LifecycleException;
import com.richie696.connect.*;

public class Connector {

    private int port;

    private String executor;

    private CatalinaExecutor executorBean;

    private String protocol;

    private ProtocolHandler protocolHandler;

    private Adapter adapter;

    private Engine engine;

    public Connector() {
        adapter = new StandardAdapter(this);
    }

    public Adapter getAdapter() {
        return adapter;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getExecutor() {
        return executor;
    }

    public void setExecutor(String executor) {
        this.executor = executor;
    }

    public CatalinaExecutor getExecutorBean() {
        return executorBean;
    }

    public void setExecutorBean(CatalinaExecutor executorBean) {
        this.executorBean = executorBean;
    }

    public void setProtocolHandler(ProtocolHandler protocolHandler) {
        this.protocolHandler = protocolHandler;
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) throws LifecycleException {
        this.protocol = protocol;
        try {
            protocolHandler = ProtocolType.nameOf(protocol).getClassName().getConstructor().newInstance();
        } catch (Exception e) {
            throw new LifecycleException(e);
        }
    }

    public ProtocolHandler getProtocolHandler() {
        return protocolHandler;
    }

    public Engine getEngine() {
        return engine;
    }

    public void setEngine(Engine engine) {
        this.engine = engine;
    }
}
